---
title: eventClick triggering
description: Click on an event to trigger eventClick
layout: demo-v4
plugins: [ daygrid ]
---
{% assign ym = site.time | date: '%Y-%m' %}
<script>

  document.addEventListener('DOMContentLoaded', function() {
    var calendarEl = document.getElementById('calendar');

    var calendar = new FullCalendar.Calendar(calendarEl, {
      plugins: [ 'dayGrid' ],
      eventClick: function(info) {
        var eventObj = info.event;

        if (eventObj.url) {
          alert(
            'Clicked ' + eventObj.title + '.\n' +
            'Will open ' + eventObj.url + ' in a new tab'
          );

          window.open(eventObj.url);

          info.jsEvent.preventDefault(); // prevents browser from following link in current tab.
        } else {
          alert('Clicked ' + eventObj.title);
        }
      },
      defaultDate: '{{ ym }}-15',
      events: [
        {
          title: 'simple event',
          start: '{{ ym }}-02'
        },
        {
          title: 'event with URL',
          url: 'https://www.google.com/',
          start: '{{ ym }}-03'
        }
      ]
    });

    calendar.render();
  });

</script>
